#include "Writer.h"

namespace Lyt
{
	namespace IO
	{
		StreamWriter::StreamWriter(IStream *ObjectStream)
		{
			Stream=ObjectStream;
		}

		StreamWriter::StreamWriter(const WString FileName)
		{
			Stream=new FileStream(FileName, modeWrite);
		}

		StreamWriter::~StreamWriter()
		{
			Close();
		}

		void StreamWriter::Close()
		{
			if (Stream) delete Stream;
			Stream=0;
		}

		bool StreamWriter::IsAvailable()const
		{
			return Stream!=0;
		}

		void StreamWriter::Write(const WString Object)
		{
			Stream->Write(Object.GetBuffer(), sizeof(wchar_t)*Object.GetLength());
		}

		void StreamWriter::WriteLine(const WString Object)
		{
			WString Result=L"\r\n"+Object;
			Stream->Write(Result.GetBuffer(), sizeof(wchar_t)*(Object.GetLength()+2));
		}
	}
}